<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Calculating with currencies - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.currency.calculation.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.currency.calculation.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.currency.value.html">How much is my currency?</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.currency.html">Zend_Currency</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.currency.exchange.html">Exchanging currencies</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.currency.calculation" class="section"><div class="info"><h1 class="title">Calculating with currencies</h1></div>
    

    <p class="para">
        When working with currencies you will sometimes also have to calculate with them.
        <span class="classname">Zend_Currency</span> allows you to do this with some simple methods.
        The following methods are supported for calculation:
    </p>

    <ul class="itemizedlist">
        <li class="listitem">
            <p class="para">
                <em class="emphasis"> <span class="methodname">add()</span></em>: This method adds the given
                currency to the existing currency object.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis"> <span class="methodname">sub()</span></em>: This method substracts the
                given currency from the existing currency object.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis"> <span class="methodname">div()</span></em>: This method divides the
                given currency from the existing currency object.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis"> <span class="methodname">mul()</span></em>: This method multiplies the
                given currency with the existing currency object.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis"> <span class="methodname">mod()</span></em>: This method calculates the
                remaining value (modulo) from dividing the given currency from the existing
                currency object.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis"> <span class="methodname">compare()</span></em>: This method compares
                the given currency with the existing currency object. When both values are
                equal it returns &#039;0&#039;. When the existing currency value is greater than the
                given, this method will return 1. Otherwise you will get &#039;-1&#039; returned.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis"> <span class="methodname">equals()</span></em>: This method compares
                the given currency with the existing currency object. When both values are
                equal it returns <b><tt>TRUE</tt></b>, otherwise
                <b><tt>FALSE</tt></b>.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis"> <span class="methodname">isMore()</span></em>: This method compares
                the given currency with the existing currency object. When the existing
                currency is greater than the given one, you will get <b><tt>TRUE</tt></b>
                in return, otherwise <b><tt>FALSE</tt></b>.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis"> <span class="methodname">isLess()</span></em>: This method compares
                the given currency with the existing currency object. When the existing
                currency is less than the given one, you will get <b><tt>TRUE</tt></b>
                in return, otherwise <b><tt>FALSE</tt></b>.
            </p>
        </li>
    </ul>

    <p class="para">
        As you can see the multiple methods allow any kind of calculation with
        <span class="classname">Zend_Currency</span>. See the next snippets as example:
    </p>

    <pre class="programlisting brush: php">
$currency = new Zend_Currency(
    array(
        &#039;value&#039;    =&gt; 1000,
        &#039;currency&#039; =&gt; &#039;USD&#039;,
    )
);

print $currency; // Could return &#039;$ 1.000,00&#039;

$currency-&gt;add(500);
print $currency; // Could return &#039;$ 1.500,00&#039;
</pre>


    <pre class="programlisting brush: php">
$currency_2 = new Zend_Currency(
    array(
        &#039;value&#039;    =&gt; 500,
        &#039;currency&#039; =&gt; &#039;USD&#039;,
    )
);

if ($currency-&gt;isMore($currency_2)) {
    print &quot;First is more&quot;;
}

$currency-&gt;div(5);
print $currency; // Could return &#039;$ 200,00&#039;
</pre>

</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.currency.value.html">How much is my currency?</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.currency.html">Zend_Currency</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.currency.exchange.html">Exchanging currencies</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.currency.html">Zend_Currency</a></li>
  <li><a href="zend.currency.introduction.html">Introduction to Zend_Currency</a></li>
  <li><a href="zend.currency.usage.html">Using Zend_Currency</a></li>
  <li><a href="zend.currency.options.html">Options for currencies</a></li>
  <li><a href="zend.currency.description.html">What makes a currency?</a></li>
  <li><a href="zend.currency.position.html">Where is the currency?</a></li>
  <li><a href="zend.currency.number.html">How does the currency look like?</a></li>
  <li><a href="zend.currency.value.html">How much is my currency?</a></li>
  <li class="active"><a href="zend.currency.calculation.html">Calculating with currencies</a></li>
  <li><a href="zend.currency.exchange.html">Exchanging currencies</a></li>
  <li><a href="zend.currency.additional.html">Additional informations on Zend_Currency</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>